<?php

use Drupal\shusy_store_order\Entity\ShusyStoreOrder;

/**
 * Implements hook_rules_action_info().
 */
function shusy_store_order_rules_action_info() {
  return [
    'shusy_store_order_rules_action_hookevent' => [
      'label' => t('触发订单hook事件'),
      'parameter' => [
        'order' => [
          'type' => 'shusy_store_order',
          'label' => t('订单'),
        ],
        'hook' => [
          'type' => 'text',
          'label' => 'HOOK类型',
          'options list' => 'shusy_store_order_hook_options',
        ],
      ],
      'group' => t('shusy_store_order'),
    ],
  ];
}

function shusy_store_order_hook_options() {
  return [
    'pay' => '支付后',
    'ship' => '发货后',
    'receipt' => '收货后',
  ];
}

function shusy_store_order_rules_action_hookevent(ShusyStoreOrder $order, string $hook) {
  drupal_alter("shusy_store_order_$hook", $order);
}
